package com.baseproject.imageload;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.app.Fragment;
import android.widget.ImageView;

import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.Transformation;

import java.io.File;


public class GlideImageLoaderStrategy implements BaseImageLoaderStrategy {

    RequestManager mRequestManager;

    DrawableRequestBuilder mDrawableRequestBuilder;


    @Override
    public BaseImageLoaderStrategy with(Context context) {
        mRequestManager = Glide.with(context);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy with(Fragment fragment) {
        mRequestManager = Glide.with(fragment);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy with(Activity activity) {
        mRequestManager = Glide.with(activity);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy load(File file) {
        mDrawableRequestBuilder = mRequestManager.load(file);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy load(String url) {
        mDrawableRequestBuilder = mRequestManager.load(url);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy placeholder(int resourceId) {
        mDrawableRequestBuilder.placeholder(resourceId);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy error(int resourceId) {
        mDrawableRequestBuilder.error(resourceId);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy dontAnimate() {
        mDrawableRequestBuilder.dontAnimate();
        return this;
    }

    @Override
    public BaseImageLoaderStrategy crossFade(int duration) {
        mDrawableRequestBuilder.crossFade(duration);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy bitmapTransform(Transformation<Bitmap>... bitmapTransformations) {
        mDrawableRequestBuilder.bitmapTransform(bitmapTransformations);
        return this;
    }

    @Override
    public BaseImageLoaderStrategy into(ImageView imageView) {
        mDrawableRequestBuilder.into(imageView);
        return this;
    }
}
